package MicroSpring.beanPostProcessor.impl;

import MicroSpring.beanFactory.impl.DefaultListableBeanFactory;
import MicroSpring.beanPostProcessor.BeanPostProcessor;

public class AspectBeansInitBeanPostProcessor implements BeanPostProcessor {
    private final DefaultListableBeanFactory beanFactory;

    public AspectBeansInitBeanPostProcessor(DefaultListableBeanFactory beanFactory) {
        this.beanFactory = beanFactory;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) {
        if (beanFactory.getAspectBeans().containsKey(beanName)){
            //需要替换成代理对象
            return beanFactory.getAspectBeans().get(beanName);
        }
        return bean;
    }
}
